package com.EmployeeButler.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestControllerAdvice
public class GlobalExceptionHandler {
    // 全局异常拦截 
    @ExceptionHandler
    public void handlerException(Exception e, HttpServletResponse response) throws IOException {
        if (e instanceof cn.dev33.satoken.exception.NotLoginException) {
            try {
                response.sendRedirect("/login");
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }

        } else {
            response.sendRedirect("/login");
            e.printStackTrace();
        }

    }
}